home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programming Languages Suite
/
ProgramD2.iso
/
Borland
/
Borland C++ V5.02
/
STDLIB.PAK
/
COMPLX.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1997-05-06
|
924b
|
40 lines
/**************************************************************************
*
* complx.cpp - Complex Number example program. Section 14.3
*
* $Id: complx.cpp,v 1.3 1995/08/29 19:00:58 oberg Exp $
*
* $$RW_INSERT_HEADER "slyrs.cpp"
*
**************************************************************************/
# include <complex>
# include <utility>
# include <iostream.h>
using namespace std;
typedef complex<double> dcomplex;
pair<dcomplex, dcomplex> quadratic
(dcomplex a, dcomplex b, dcomplex c)
// return roots of a quadratic equation
{
dcomplex root = sqrt(b * b - 4.0 * a * c);
a = a * 2.0;
return make_pair (
(-b + root) / a,
(-b - root) / a);
}
int main() {
dcomplex a(2, 3);
dcomplex b(4, 5);
dcomplex c(6, 7);
pair<dcomplex, dcomplex> ans = quadratic(a, b, c);
cout << "Roots are " << ans.first << " and " << ans.second << endl;
return 0;
}